package com.example.lenovo.demob;
/**
 *    添加学生界面
 */

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class AddStudentActivity extends AppCompatActivity {
    private EditText edit_no,edit_name,edit_age,edit_sex;
    private Button btn_add;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_add_student);
        //定义组件
        findViews();

        //添加学生
        AddStus();
    }

    private void AddStus() {
        btn_add=findViewById(R.id.btn_add);
        btn_add.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String no=edit_no.getText().toString();
                String name=edit_name.getText().toString();
                int age=Integer.parseInt(edit_age.getText().toString());
                String sex=edit_sex.getText().toString();
                Intent intent=new Intent();
                intent.putExtra("NO",no);
                intent.putExtra("NAME",name);
                intent.putExtra("AGE",age);
                intent.putExtra("SEX",sex);
                setResult(2001,intent);
                finish();
            }
        });
    }

    /**
     *  定义组件
     */
    private void findViews() {
        edit_no=findViewById(R.id.edit_no);
        edit_name=findViewById(R.id.edit_name);
        edit_age=findViewById(R.id.edit_age);
        edit_sex=findViewById(R.id.edit_sex);

    }
}
